home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / listbnd.fr_ / listbnd.fr
Text File  |  1995-07-04  |  10KB  |  311 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Bound Lister"
  5.    ClientHeight    =   2685
  6.    ClientLeft      =   1905
  7.    ClientTop       =   1785
  8.    ClientWidth     =   6420
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   1
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   3375
  19.    Left            =   1845
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   2685
  22.    ScaleWidth      =   6420
  23.    Top             =   1155
  24.    Width           =   6540
  25.    Begin VB.Data dtaPublishers 
  26.       Caption         =   "Data1"
  27.       Connect         =   "Access"
  28.       DatabaseName    =   "C:\VB\BIBLIO.MDB"
  29.       Exclusive       =   0   'False
  30.       Height          =   300
  31.       Left            =   3180
  32.       Options         =   0
  33.       ReadOnly        =   0   'False
  34.       RecordsetType   =   1  'Dynaset
  35.       RecordSource    =   "Publishers"
  36.       Top             =   1980
  37.       Visible         =   0   'False
  38.       Width           =   1635
  39.    End
  40.    Begin VB.TextBox txtISBN 
  41.       DataField       =   "ISBN"
  42.       DataSource      =   "dtaTitles"
  43.       Height          =   315
  44.       Left            =   4260
  45.       MaxLength       =   13
  46.       TabIndex        =   2
  47.       Top             =   900
  48.       Width           =   1635
  49.    End
  50.    Begin VB.TextBox txtYearPublished 
  51.       DataField       =   "Year Published"
  52.       DataSource      =   "dtaTitles"
  53.       Height          =   285
  54.       Left            =   1860
  55.       TabIndex        =   1
  56.       Top             =   900
  57.       Width           =   735
  58.    End
  59.    Begin VB.TextBox txtTitle 
  60.       DataField       =   "Title"
  61.       DataSource      =   "dtaTitles"
  62.       Height          =   555
  63.       Left            =   1860
  64.       MultiLine       =   -1  'True
  65.       TabIndex        =   0
  66.       Top             =   180
  67.       Width           =   4095
  68.    End
  69.    Begin VB.Data dtaTitles 
  70.       Caption         =   "Titles"
  71.       Connect         =   "Access"
  72.       DatabaseName    =   "C:\VB\BIBLIO.MDB"
  73.       EOFAction       =   2  'Add New
  74.       Exclusive       =   0   'False
  75.       Height          =   300
  76.       Left            =   660
  77.       Options         =   0
  78.       ReadOnly        =   0   'False
  79.       RecordsetType   =   1  'Dynaset
  80.       RecordSource    =   "Titles"
  81.       Top             =   2040
  82.       Width           =   1815
  83.    End
  84.    Begin MSDBCtls.DBCombo dbcPublishers 
  85.       Bindings        =   "LISTBND.frx":0000
  86.       DataField       =   "PubID"
  87.       DataSource      =   "dtaTitles"
  88.       Height          =   315
  89.       Left            =   1800
  90.       TabIndex        =   7
  91.       Top             =   1320
  92.       Width           =   4095
  93.       _version        =   65536
  94.       _extentx        =   7223
  95.       _extenty        =   556
  96.       _stockprops     =   77
  97.       backcolor       =   16777215
  98.       style           =   2
  99.       listfield       =   "Name"
  100.       boundcolumn     =   "PubID"
  101.    End
  102.    Begin VB.Label Label4 
  103.       AutoSize        =   -1  'True
  104.       BackColor       =   &H00C0C0C0&
  105.       Caption         =   "Publisher ID:"
  106.       Height          =   195
  107.       Left            =   600
  108.       TabIndex        =   6
  109.       Top             =   1380
  110.       Width           =   1110
  111.    End
  112.    Begin VB.Label Label3 
  113.       AutoSize        =   -1  'True
  114.       BackColor       =   &H00C0C0C0&
  115.       Caption         =   "ISBN:"
  116.       Height          =   195
  117.       Left            =   3600
  118.       TabIndex        =   5
  119.       Top             =   960
  120.       Width           =   510
  121.    End
  122.    Begin VB.Label Label2 
  123.       AutoSize        =   -1  'True
  124.       BackColor       =   &H00C0C0C0&
  125.       Caption         =   "Year Published:"
  126.       Height          =   195
  127.       Left            =   360
  128.       TabIndex        =   4
  129.       Top             =   960
  130.       Width           =   1350
  131.    End
  132.    Begin VB.Label Label1 
  133.       AutoSize        =   -1  'True
  134.       BackColor       =   &H00C0C0C0&
  135.       Caption         =   "Title:"
  136.       Height          =   195
  137.       Left            =   1200
  138.       TabIndex        =   3
  139.       Top             =   180
  140.       Width           =   450
  141.    End
  142.    Begin VB.Menu mnuFile 
  143.       Caption         =   "&File"
  144.       Begin VB.Menu mnuFileExit 
  145.          Caption         =   "E&xit"
  146.       End
  147.    End
  148.    Begin VB.Menu mnuEdit 
  149.       Caption         =   "&Edit"
  150.       Begin VB.Menu mnuEditUndo 
  151.          Caption         =   "&Undo"
  152.          Shortcut        =   %{BKSP}
  153.       End
  154.    End
  155.    Begin VB.Menu mnuData 
  156.       Caption         =   "&Data"
  157.       Begin VB.Menu mnuDataAddRecord 
  158.          Caption         =   "&Add Record"
  159.       End
  160.       Begin VB.Menu mnuDataDeleteRecord 
  161.          Caption         =   "&Delete Record"
  162.       End
  163.       Begin VB.Menu mnuDataSaveRecord 
  164.          Caption         =   "&Save Record"
  165.       End
  166.    End
  167. End
  168. Attribute VB_Name = "Form1"
  169. Attribute VB_Creatable = False
  170. Attribute VB_Exposed = False
  171. Option Explicit
  172.  
  173. Private UpdateCancelled As Boolean
  174.  
  175.  
  176.  
  177.  
  178. Private Sub dtaTitles_Validate(Action As Integer, Save As Integer)
  179.     Dim msg As String
  180.  
  181.     'MsgBox Str$(Action) & "  " & Str$(Save) & "  " & dtaTitles.EditMode
  182.     UpdateCancelled = False
  183.  
  184.     If Save = True Or Action = vbDataActionUpdate _
  185.         Or dtaTitles.Recordset.EditMode = dbEditAdd _
  186.     Then
  187.     
  188.         ' Either one or more bound controls has changed, or the Update
  189.         ' method was invoked from code, or we're adding a new record.
  190.         ' So verify that all fields have legal entries. If a field has
  191.         ' an incorrect value, set the variable msg to a string explaining
  192.         ' the error and set the focus to that field to facilitate the user's
  193.         ' correcting the error.
  194.         If txtTitle = "" Then
  195.              msg = "You must enter a title."
  196.              txtTitle.SetFocus
  197.         ElseIf txtISBN = "" Then
  198.              msg = "You must enter an ISBN."
  199.              txtISBN.SetFocus
  200.         ElseIf txtYearPublished <> "" And Not IsNumeric(txtYearPublished) Then
  201.             msg = "The Year Published must be numeric."
  202.             txtYearPublished.SetFocus
  203.         ElseIf dbcPublishers.Text = "" Then
  204.             msg = "You must enter a numeric Publisher ID."
  205.             dbcPublishers.SetFocus
  206.         End If
  207.     End If
  208.     If msg <> "" Then
  209.  
  210.         ' We have something in the variable msg, which means that an error
  211.         ' has occurred. Display the message for the user.
  212.         MsgBox msg, vbExclamation
  213.         
  214.        ' Cancel the Validate event
  215.         Action = vbDataActionCancel
  216.         
  217.         ' Set the form-level variable UpdateCancelled to True. This flags
  218.         ' the Unload event to cancel the unload.
  219.         UpdateCancelled = True
  220.         
  221.     Else
  222.     
  223.         ' No errors, so set the form level variable UpdateCancelled False
  224.         ' to flag the Unload event to go ahead and proceed with the unload.
  225.         UpdateCancelled = False
  226.     End If
  227. End Sub
  228.  
  229. Private Sub mnuEditUndo_Click()
  230.     If dtaTitles.EditMode = dbEditAdd Then
  231.     
  232.         ' The user clicked Undo while adding a new record, so cancel the
  233.         ' AddNew operation.
  234.         dtaTitles.Recordset.CancelUpdate
  235.         
  236.         ' Now make a valid record the current record.
  237.         dtaTitles.Recordset.MoveLast
  238.     Else
  239.     
  240.         ' The user clicked Undo while editing an existing record, so reset
  241.         ' values in the controls to values from the current recordset record.
  242.         dtaTitles.UpdateControls
  243.     End If
  244. End Sub
  245.  
  246.  
  247. Private Sub mnuFileExit_Click()
  248.     Unload Me
  249. End Sub
  250.  
  251. Private Sub Form_Unload(Cancel As Integer)
  252.  
  253.     If UpdateCancelled Then
  254.         
  255.         ' The Validate event failed, so cancel the unload.
  256.         Cancel = True
  257.         
  258.     ElseIf dtaTitles.Recordset.EditMode = dbEditAdd Then
  259.     
  260.         ' The Validate event succeeded, so write the new record to the
  261.         ' recordset.
  262.         dtaTitles.Recordset.Update
  263.     End If
  264.     
  265. End Sub
  266.  
  267. Private Sub mnuDataSaveRecord_Click()
  268.  
  269.     ' The user clicked SaveRecord, so call the Update method to transfer
  270.     ' the values in the bound controls to their respective fields.
  271.     dtaTitles.Recordset.Update
  272. End Sub
  273.  
  274. Private Sub mnuDataAddRecord_Click()
  275.  
  276.     ' The user clicked Add Record. Reset all controls to the default for a
  277.     ' new record and make space in the copy buffer for a new recpord.
  278.     dtaTitles.Recordset.AddNew
  279.     
  280.     ' The default for Year Published in the database is 0. Change it to
  281.     ' nothing.
  282.     txtYearPublished = ""
  283.     
  284.     
  285.     ' Set the focus to the first control on the form.
  286.     txtTitle.SetFocus
  287. End Sub
  288.  
  289. Private Sub mnuDataDeleteRecord_Click()
  290.     Dim msg As String
  291.  
  292.     ' Verify that the user wants to delete the record.
  293.     msg = "Are you sure you want to delete "
  294.     msg = msg & IIf(txtTitle <> "", txtTitle, "this record") & "?"
  295.     If MsgBox(msg, vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
  296.     
  297.         ' The user wants to delete, so delete the record.
  298.         dtaTitles.Recordset.Delete
  299.         
  300.         ' Make a valid record the current record.
  301.         dtaTitles.Recordset.MoveNext
  302.         
  303.         ' If we just deleted the last record in the recordset,
  304.         ' position the recordpointer on the new last record.
  305.         If dtaTitles.Recordset.EOF Then dtaTitles.Recordset.MoveLast
  306.     End If
  307. End Sub
  308.  
  309.  
  310.  
  311.